home *** CD-ROM | disk | FTP | other *** search
- /* PC98<->FMR ファイル転送 for FMR/PC98 Copyright (c) E.Suto , 1992-1993 */
- /* 修正履歴 Ver 0.00 1992/06/14 試作品 */
- /* Ver 0.10 1992/06/15 高速化 */
- /* Ver 0.20 1992/06/15 ワイルドカードサポート */
- /* Ver 1.00 1992/06/16 後悔じゃなくて公開版 */
- /* Ver 1.10 1992/06/17 ファイル属性,日付及び時間の転送 */
- /* Ver 1.11 1992/06/25 OS/2&共用ドライブ対応/¥バグ修正 */
- /* Ver 1.12 1992/06/25 ちょっと高速化(^^;と相手待ちのESC停止 */
- /* Ver 2.00 1992/06/25 簡易サーバーモード追加 */
- /* Ver 2.10 1992/06/26 簡易リモートコマンド追加 */
- /* Ver 2.30 1992/07/01 TIMEOUT()改造,オプション統合,速度表示 */
- /* Ver 2.31 1992/07/02 簡易サーバーを出来るだけ止めないよう */
- /* Ver 2.32 1992/07/03 速度表示の0割り算ガード(超手抜き) */
- /* Ver 2.33 1992/07/06 . の消し方変更 */
- /* Ver 2.34 1992/07/09 受信ファイルがルートに行ってしまうバグ修正 */
- /* Ver 2.35 1992/11/17 RS232Cのバグ修正 */
- /* Ver 2.36 1992/11/17 ちょっと高速化(^^; */
- /* Ver 2.37 1992/11/17 もうちょっと高速化(^^;; */
- /* Ver 2.38 1992/11/17 もうちょびっと高速化(^^;;; */
- /* Ver 2.39 1992/11/18 タイマ値最適化 */
- /* Ver 2.40 1992/11/18 送信ファイル名バグ修正 */
- /* Ver 2.41 1992/12/11 inpにwait-loop(;_;) */
- /* Ver 2.42 1992/12/11 inpにwait-loop(;_;)の改良?でも止め(^^;*/
- /* Ver 2.43 1993/ 2/ 2 関数を変数で呼び出す */
- /* Ver 2.44 1993/ 2/ 3 失敗時にタイムアウトしない */
- /* Ver 2.45 1993/ 2/ 4 コマンド受信処理でタイムアウトしない */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <dos.h>
- #include <io.h>
- #include <fcntl.h>
- #include <signal.h>
- #include <string.h>
- #include <time.h>
- #include <sys\timeb.h>
-
- #define BUFFSIZE 32767
- #define PALAWAIT 0 /* TIMEOUTが発生する場合はこの値を大きくしてね(^^; */
-
- void copyright() ;
- int connect_r() ;
- int connect_s() ;
- void fp_command() ;
- void fp_file() ;
- void fp_path() ;
- void fp_send() ;
- void fp_server() ;
- void fp_receive() ;
- void fp_receive0() ; /* (^^;;;; */
- void m_check() ;
- void m_set() ;
- int (*receive_)( int , unsigned char * ) ;
- int receive_f( int , unsigned char * ) ;
- int receive_p( int , unsigned char * ) ;
- void rs_init() ;
- int (*send_)( int , unsigned char * ) ;
- int send_f( int , unsigned char * ) ;
- int send_p( int , unsigned char * ) ;
- void sig_out() ;
- void timeout() ;
- void timeset() ;
- void usage() ;
-
- static int machine ; /* 機種 0:FMR 1:PC98 */
- static int mode ; /* 動作モード 0:S 1:R 2:サ 3:サS 4:サR 5:*/
- static unsigned int rs_in ; /* RS_232Cステータスアドレス */
- static unsigned int rs_out ; /* RS_232Cコマンドアドレス */
- static unsigned char rs_rev ; /* RS_232Cステータス反転マスク値 */
- static unsigned char rs_mask ; /* RS_232Cステータスマスク値 */
- static unsigned char rs_ci ; /* RS_232CCI_ONチェック値 */
- static unsigned char rs_cd ; /* RS_232CCD_ONチェック値 */
- static unsigned char rs_cics ; /* RS_232CCS/CI ON */
- static unsigned char name[128] ; /* 操作ファイル名 */
- static unsigned char path[128] ; /* 送信先パス名 */
- static unsigned char command[128]; /* 送信コマンド */
- static unsigned char buffer[BUFFSIZE];/* バッファ */
- struct find_t f_name ; /* ワイルドカード展開データ */
- struct timeb time_1 ; /* 速度計算用タイマ値1 */
- struct timeb time_2 ; /* 速度計算用タイマ値2 */
- static long timeout1 ; /* タイムアウト値 */
- static int debug ; /* 詳細表示 */
-
-
- void main(int argc,char *argv[])
- {
- int i , k , l , m ;
- unsigned char *c ;
-
- debug = 0 ;
- mode = -1 ;
- machine = -1 ;
- strcpy( path , "" ) ;
- strcpy( command , "" ) ;
-
- /* コピーライト表示 */
- copyright() ;
-
- /* 割り込み処理定義 */
- signal( SIGINT , sig_out ) ;
-
- /* オプションチェック */
- if( argc < 2 ) {
- usage() ;
- exit( 0 ) ;
- }
- else {
- k = l = 0 ;
- for( i=1 ; i < argc ; i++ ) {
- c = argv[i] ;
- if( *c == '-' || *c == '/' ) {
- switch( *++c ) {
- case '?' :
- usage();
- exit( 0 );
- case 'i' :
- case 'I' :
- debug = -1 ;
- break ;
- case 'R' :
- case 'r' :
- if( k ) mode = 4 ;
- else mode = 1 ;
- break ;
- case 'S' :
- case 's' :
- mode = 0 ;
- break ;
- case 'Z' :
- case 'z' :
- mode = 2 ;
- break ;
- case 'C' :
- case 'c' :
- mode = 5 ;
- c++ ;
- strcpy( command , c ) ;
- if( command[0] == '"' ) {
- for( ; i < argc ; ) {
- i++ ;
- strcat( command , " " ) ;
- strcat( command , argv[i] ) ;
- if( command[strlen( command ) - 1 ] == '"' )
- break ;
- }
- }
- break ;
- case 'X' :
- case 'x' :
- c++ ;
- strcpy( path , c ) ;
- l = -1 ;
- break ;
- case 'P' :
- case 'p' :
- machine = 1 ;
- break ;
- case 'F' :
- case 'f' :
- machine = 0 ;
- break ;
- default :
- perr: printf( "ファイル名が2つ以上指定されているか、誤ったパラメタ(%s)が指定されています。\n" , argv[i] ) ;
- usage() ;
- exit( -1 ) ;
- }
- }
- else {
- if( mode == 5 ) {
- if( strlen( command ) > 0 ) goto perr ;
- strcpy( command , c ) ;
- if( command[0] == '"' ) {
- for( ; i < argc ; ) {
- i++ ;
- strcat( command , " " ) ;
- strcat( command , argv[i] ) ;
- if( command[strlen( command ) - 1 ] == '"' )
- break ;
- }
- }
- else {
- for( ; i < argc ; ) {
- i++ ;
- if( ( *(argv[i]) == '-' ) || ( *(argv[i]) == '/' ) )
- break ;
- strcat( command , " " ) ;
- strcat( command , argv[i] ) ;
- }
- }
- }
- else {
- if( k ) goto perr ;
- strcpy( name , argv[i] ) ;
- k = -1 ;
- if( mode == 1 ) mode = 4 ;
- }
- }
- }
- }
-
- /* オプションの関連チェック */
- if( mode == -1 ) {
- printf( "-r,-s,-z又は-c,の何れかを指定してください。\n" ) ;
- usage() ;
- exit( -1 ) ;
- }
- if( !( k ) && ( mode == 0 ) ) {
- printf( "-s指定時にはファイル名を省略できません。\n" ) ;
- usage() ;
- exit( -1 ) ;
- }
- if( l && ( mode != 0 ) ) {
- printf( "-s 指定時以外にはでは、-xは指定できません。\n" ) ;
- usage() ;
- exit( -1 ) ;
- }
- if( mode == 5 ) {
- strcpy( buffer , command ) ;
- if( buffer[0] == '"' ) {
- m = strlen( buffer ) ;
- if( buffer[m-1] != '"' ) {
- printf( "コマンドの終わりを示す\"が不足しています。(%s)\n",buffer ) ;
- usage() ;
- exit( -1 ) ;
- }
- buffer[m-1] = 0x00 ;
- strcpy( command , ( buffer + 1 ) ) ;
- }
- if( strlen( command ) == 0 ) {
- printf( "-c に続いてリモートコマンドを指定してください。\n" ) ;
- usage() ;
- exit( -1 ) ;
- }
- if( strlen( command ) > 114 ) {
- printf( "申し訳有りませんがコマンドが長すぎます。114文字以下にしてください。\n" ) ;
- usage() ;
- exit( -1 ) ;
- }
- }
-
- /* 機種判定 */
- if( machine == -1 ) m_check() ;
- m_set() ;
-
- /* タイムアウト値設定 */
- timeset() ;
-
- /* 回線の初期化 */
- rs_init() ;
-
- /* 送受信処理へ */
- switch( mode ) {
- case 0 : /* 送信処理 */
- connect_s() ;
- fp_send() ;
- break ;
- case 1 : /* 受信処理 */
- connect_r() ;
- fp_receive0() ;
- fp_receive() ;
- break ;
- case 2 : /* サーバー処理 */
- fp_server() ;
- break ;
- case 4 : /* サーバーからの受信処理 */
- connect_s() ;
- fp_file() ;
- fp_receive0() ;
- fp_receive() ;
- break ;
- case 5 : /* リモートコマンド処理 */
- connect_s() ;
- fp_command() ;
- break ;
- }
-
- /* 後始末 */
- printf( "電送処理終了しました。\n" ) ;
- rs_init() ;
-
- }
-
- /* 手抜き機種判定(まねしない方が良いですよ(^^;) */
- void m_check()
- {
- machine = -1 ;
-
- /* PC98の判定 */
-
- if( ( inp( 0x0032 ) & 0x3e ) == 0x04 ) {
- machine = 1 ; /* PC98かな? */
- }
- else if( inp( 0x0a02 ) != 0xff ) {
- machine = 0 ; /* FMRかな? */
- }
-
- if( machine == -1 ) {
- printf( "ごめんなさい機種がわからないの(;_;) -f か -p を指定してね。\n" ) ;
- exit( -1 ) ;
- }
-
- if( debug ) {
- if( machine ) printf( "たぶんPC98と思う。\n" ) ;
- else printf( "たぶんFMRと思う。\n" ) ;
- }
-
- }
-
- /* 機種情報設定 */
- void m_set()
- {
-
- /* PC98の設定 */
- if( machine ) {
- rs_in = 0x0033 ;
- rs_out = 0x0032 ;
- rs_rev = 0xff ;
- rs_mask = 0xe0 ;
- rs_cd = 0x20 ;
- rs_ci = 0x80 ;
- rs_cics = 0xc0 ;
- send_ = send_p ;
- receive_ = receive_p ;
- }
-
- /* FMRの設定 */
- else {
- rs_in = 0x0a04 ;
- rs_out = 0x0a02 ;
- rs_rev = 0x00 ;
- rs_mask = 0x07 ;
- rs_cd = 0x04 ;
- rs_ci = 0x01 ;
- rs_cics = 0x03 ;
- send_ = send_f ;
- receive_ = receive_f ;
- }
-
- }
-
- /* 8251の初期化 */
- void rs_init()
- {
- int i , j ;
-
- /* 状態のリセット */
- for( i = 0 ; i < 3 ; i++ ) {
- outp( rs_out , 0x00 ) ;
- for( j = 0 ; j < 3 ; j++ ) ; /* 念のため時間待ち */
- }
- outp( rs_out , 0x40) ;
-
- /* モードセット */
- outp( rs_out , 0x4e) ;
- for( j = 0 ; j < 6 ; j++ ) ; /* 念のため時間待ち */
-
- /* エラーリセット/コマンドセット */
- outp( rs_out , 0x37) ;
- for( j = 0 ; j < 6 ; j++ ) ; /* 念のため時間待ち */
-
- }
-
- /* 接続確認待ち(送信型)*/
- int connect_s()
- {
- unsigned char stat ;
-
- /* 接続確認 */
- if( mode != 2 ) printf( "接続待ちです。\n" ) ;
- outp( rs_out , 0x02 ) ; /* ずーと待つからsendは使わない */
- stat = rs_ci ;
- while( ( ( inp( rs_in ) ^ rs_rev ) & rs_mask ) != stat ) {
- printf( "*\r" ) ;
- if( kbhit() ) {
- if( getch() == 0x1b ) sig_out() ;
- }
- }
-
- outp( rs_out , 0x2a ) ; /* ずーと待つからsendは使わない */
- stat = rs_cd | rs_cics ;
- while( ( ( inp( rs_in ) ^ rs_rev ) & rs_mask ) != stat ) {
- printf( "*\r" ) ;
- if( kbhit() ) {
- if( getch() == 0x1b ) sig_out() ;
- }
- }
-
- buffer[0] = 0xe4 ; /* このへんの文字は何でも良い(^^; */
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return( -1 ) ;
- else timeout() ;
- }
- if( debug ) printf( "送信型接続OK。\n" ) ;
- return( 0 ) ;
-
- }
-
- /* 接続確認待ち(受信型)*/
- int connect_r()
- {
- unsigned char stat ;
-
- /* 接続確認 */
- if( mode != 2 ) printf( "接続待ちです。\n" ) ;
- stat = rs_ci ;
- while( ( ( inp( rs_in ) ^ rs_rev ) & rs_mask ) != stat ) {
- printf( "*\r" ) ;
- if( kbhit() ) {
- if( getch() == 0x1b ) sig_out() ;
- }
- }
- outp( rs_out , 0x02 ) ; /* ずっと待ちたいからreceiveを使わない */
-
- stat = rs_cd | rs_cics ;
- while( ( ( inp( rs_in ) ^ rs_rev ) & rs_mask ) != stat ) {
- printf( "*\r" ) ;
- if( kbhit() ) {
- if( getch() == 0x1b ) sig_out() ;
- }
- }
- outp( rs_out , 0x2a ) ; /* ずっと待ちたいからreceiveを使わない */
-
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return( -1 ) ;
- timeout() ;
- }
- if( buffer[0] != 0xe4 ) { /* このへんの文字は送信側に合わせる */
- printf( "接続確認処理でエラーが発生しました。\n" ) ;
- if( mode == 2 ) return( -1 ) ;
- rs_init() ;
- exit( -1 ) ;
- }
- if( debug ) printf( "受信型接続OK。\n" ) ;
- return( 0 ) ;
-
- }
-
- /* 回線送信処理 Fj */
- int send_f( int l , unsigned char *b )
- {
- int i ;
- long k ;
- unsigned char stat0,stat1,data ;
-
- /* 1バイトを4つに区切って2ビット毎に送信 */
- for( i = 0 ; i < l ; i++ ) {
- /* ビット7ビット6送信 */
- data = stat0 = 0x00 ;
- switch( (*b) & 0xc0 ) {
- case 0xc0 :
- data |= 0x22 ;
- stat0 |= 0x03 ;
- break ;
- case 0x80 :
- data |= 0x20 ;
- stat0 |= 0x02 ;
- break ;
- case 0x40 :
- data |= 0x02 ;
- stat0 |= 0x01 ;
- break ;
- }
- outp( 0x0a02 , data ) ;
- /* ビット5ビット4送信 */
- data = 0x08 ;
- stat1 = 0x04 ;
- switch( (*b) & 0x30 ) {
- case 0x30 :
- data |= 0x22 ;
- stat1 |= 0x03 ;
- break ;
- case 0x20 :
- data |= 0x20 ;
- stat1 |= 0x02 ;
- break ;
- case 0x10 :
- data |= 0x02 ;
- stat1 |= 0x01 ;
- break ;
- }
- for( k = timeout1 ; ( ( inp( 0x0a04 ) ) & 0x07 ) != stat0
- ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- outp( 0x0a02 , data ) ;
- /* ビット3ビット2送信 */
- data = stat0 = 0x00 ;
- switch( (*b) & 0x0c ) {
- case 0x0c :
- data |= 0x22 ;
- stat0 |= 0x03 ;
- break ;
- case 0x08 :
- data |= 0x20 ;
- stat0 |= 0x02 ;
- break ;
- case 0x04 :
- data |= 0x02 ;
- stat0 |= 0x01 ;
- break ;
- }
- for( k = timeout1 ; ( ( inp( 0x0a04 ) ) & 0x07 ) != stat1
- ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- outp( 0x0a02 , data ) ;
- /* ビット1ビット0送信 */
- data = 0x08 ;
- stat1 = 0x04 ;
- switch( (*b) & 0x03 ) {
- case 0x03 :
- data |= 0x22 ;
- stat1 |= 0x03 ;
- break ;
- case 0x02 :
- data |= 0x20 ;
- stat1 |= 0x02 ;
- break ;
- case 0x01 :
- data |= 0x02 ;
- stat1 |= 0x01 ;
- break ;
- }
- for( k = timeout1 ; ( ( inp( 0x0a04 ) ) & 0x07 ) != stat0
- ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- outp( 0x0a02 , data ) ;
- for( k = timeout1 ; ( ( inp( 0x0a04 ) ) & 0x07 ) != stat1
- ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- /* 次のバイト処理へ */
- b++ ;
- }
- return( 0 ) ;
-
- }
-
- /* 回線送信処理 NEC */
- int send_p( int l , unsigned char *b )
- {
- int i ;
- long k ;
- unsigned char stat0,stat1,data ;
-
- /* 1バイトを4つに区切って2ビット毎に送信 */
- for( i = 0 ; i < l ; i++ ) {
- /* ビット7ビット6送信 */
- data = stat0 = 0x00 ;
- switch( (*b) & 0xc0 ) {
- case 0xc0 :
- data |= 0x22 ;
- stat0 |= 0xc0 ;
- break ;
- case 0x80 :
- data |= 0x20 ;
- stat0 |= 0x40 ;
- break ;
- case 0x40 :
- data |= 0x02 ;
- stat0 |= 0x80 ;
- break ;
- }
- outp( 0x0032 , data ) ;
- /* ビット5ビット4送信 */
- data = 0x08 ;
- stat1 = 0x20 ;
- switch( (*b) & 0x30 ) {
- case 0x30 :
- data |= 0x22 ;
- stat1 |= 0xc0 ;
- break ;
- case 0x20 :
- data |= 0x20 ;
- stat1 |= 0x40 ;
- break ;
- case 0x10 :
- data |= 0x02 ;
- stat1 |= 0x80 ;
- break ;
- }
- for( k = timeout1 ; ( ( inp( 0x0033 ) ^ 0xff ) & 0xe0 ) != stat0
- ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- outp( 0x0032 , data ) ;
- /* ビット3ビット2送信 */
- data = stat0 = 0x00 ;
- switch( (*b) & 0x0c ) {
- case 0x0c :
- data |= 0x22 ;
- stat0 |= 0xc0 ;
- break ;
- case 0x08 :
- data |= 0x20 ;
- stat0 |= 0x40 ;
- break ;
- case 0x04 :
- data |= 0x02 ;
- stat0 |= 0x80 ;
- break ;
- }
- for( k = timeout1 ; ( ( inp( 0x0033 ) ^ 0xff ) & 0xe0 ) != stat1
- ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- outp( 0x0032 , data ) ;
- /* ビット1ビット0送信 */
- data = 0x08 ;
- stat1 = 0x20 ;
- switch( (*b) & 0x03 ) {
- case 0x03 :
- data |= 0x22 ;
- stat1 |= 0xc0 ;
- break ;
- case 0x02 :
- data |= 0x20 ;
- stat1 |= 0x40 ;
- break ;
- case 0x01 :
- data |= 0x02 ;
- stat1 |= 0x80 ;
- break ;
- }
- for( k = timeout1 ; ( ( inp( 0x0033 ) ^ 0xff ) & 0xe0 ) != stat0
- ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- outp( 0x0032 , data ) ;
- for( k = timeout1 ; ( ( inp( 0x0033 ) ^ 0xff ) & 0xe0 ) != stat1
- ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- /* 次のバイト処理へ */
- b++ ;
- }
- return( 0 ) ;
-
- }
-
- /* 回線受信処理 Fj */
- int receive_f( int l , unsigned char *b )
- {
- int i , j ;
- long k ;
- unsigned char stat,data ;
-
- /* 2ビットを4つ受信で1バイト */
- for( i = 0 ; i < l ; i++ ) {
- *b = 0x00 ;
- /* ビット7ビット6受信 */
- data = 0x00 ;
- for( k = timeout1 ; ( inp( 0x0a04 ) ) & 0x04 ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- for( j = 0 ; j < PALAWAIT ; j++ ) ;
- stat = inp( 0x0a04 ) ;
- if( stat & 0x02 ) {
- (*b) |= 0x80 ;
- data |= 0x20 ;
- }
- if( stat & 0x01 ) {
- (*b) |= 0x40 ;
- data |= 0x02 ;
- }
- outp( 0x0a02 , data ) ;
- /* ビット5ビット4受信 */
- data = 0x08 ;
- for( k = timeout1 ; !( ( inp( 0x0a04 ) ) & 0x04 ) ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- for( j = 0 ; j < PALAWAIT ; j++ ) ;
- stat = inp( 0x0a04 ) ;
- if( stat & 0x02 ) {
- (*b) |= 0x20 ;
- data |= 0x20 ;
- }
- if( stat & 0x01 ) {
- (*b) |= 0x10 ;
- data |= 0x02 ;
- }
- outp( 0x0a02 , data ) ;
- /* ビット3ビット2受信 */
- data = 0x00 ;
- for( k = timeout1 ; ( inp( 0x0a04 ) ) & 0x04 ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- for( j = 0 ; j < PALAWAIT ; j++ ) ;
- stat = inp( 0x0a04 ) ;
- if( stat & 0x02 ) {
- (*b) |= 0x08 ;
- data |= 0x20 ;
- }
- if( stat & 0x01 ) {
- (*b) |= 0x04 ;
- data |= 0x02 ;
- }
- outp( 0x0a02 , data ) ;
- /* ビット1ビット0受信 */
- data = 0x08 ;
- for( k = timeout1 ; !( ( inp( 0x0a04 ) ) & 0x04 ) ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- for( j = 0 ; j < PALAWAIT ; j++ ) ;
- stat = inp( 0x0a04 ) ;
- if( stat & 0x02 ) {
- (*b) |= 0x02 ;
- data |= 0x20 ;
- }
- if( stat & 0x01 ) {
- (*b) |= 0x01 ;
- data |= 0x02 ;
- }
- outp( 0x0a02 , data ) ;
- /* 次のバイト処理へ */
- b++ ;
- }
- return( 0 ) ;
-
- }
-
- /* 回線受信処理 NEC */
- int receive_p( int l , unsigned char *b )
- {
- int i , j ;
- long k ;
- unsigned char stat,data ;
-
- /* 2ビットを4つ受信で1バイト */
- for( i = 0 ; i < l ; i++ ) {
- *b = 0x00 ;
- /* ビット7ビット6受信 */
- data = 0x00 ;
- for( k = timeout1 ; ( inp( 0x0033 ) ^ 0xff ) & 0x20 ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- for( j = 0 ; j < PALAWAIT ; j++ ) ;
- stat = inp( 0x0033 ) ^ 0xff ;
- if( stat & 0x40 ) {
- (*b) |= 0x80 ;
- data |= 0x20 ;
- }
- if( stat & 0x80 ) {
- (*b) |= 0x40 ;
- data |= 0x02 ;
- }
- outp( 0x0032 , data ) ;
- /* ビット5ビット4受信 */
- data = 0x08 ;
- for( k = timeout1 ; !( ( inp( 0x0033 ) ^ 0xff ) & 0x20 ) ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- for( j = 0 ; j < PALAWAIT ; j++ ) ;
- stat = inp( 0x0033 ) ^ 0xff ;
- if( stat & 0x40 ) {
- (*b) |= 0x20 ;
- data |= 0x20 ;
- }
- if( stat & 0x80 ) {
- (*b) |= 0x10 ;
- data |= 0x02 ;
- }
- outp( 0x0032 , data ) ;
- /* ビット3ビット2受信 */
- data = 0x00 ;
- for( k = timeout1 ; ( inp( 0x0033 ) ^ 0xff ) & 0x20 ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- for( j = 0 ; j < PALAWAIT ; j++ ) ;
- stat = inp( 0x0033 ) ^ 0xff ;
- if( stat & 0x40 ) {
- (*b) |= 0x08 ;
- data |= 0x20 ;
- }
- if( stat & 0x80 ) {
- (*b) |= 0x04 ;
- data |= 0x02 ;
- }
- outp( 0x0032 , data ) ;
- /* ビット1ビット0受信 */
- data = 0x08 ;
- for( k = timeout1 ; !( ( inp( 0x0033 ) ^ 0xff ) & 0x20 ) ; k-- ) {
- if( !( k ) ) return( -1 ) ;
- }
- for( j = 0 ; j < PALAWAIT ; j++ ) ;
- stat = inp( 0x0033 ) ^ 0xff ;
- if( stat & 0x40 ) {
- (*b) |= 0x02 ;
- data |= 0x20 ;
- }
- if( stat & 0x80 ) {
- (*b) |= 0x01 ;
- data |= 0x02 ;
- }
- outp( 0x0032 , data ) ;
- /* 次のバイト処理へ */
- b++ ;
- }
- return( 0 ) ;
-
- }
-
- /* コピーライト表示 */
- void copyright()
- {
- printf(
- "FMR <=> PC98 ファイル電送 Ver 2.45, Copyright (C) E.Suto , 1992-1993\n"
- ) ;
- }
-
- /* 使い方表示 */
- void usage()
- {
- printf( "使用方法 : FPLINK [options] [file-name]\n" ) ;
- printf( "オプション -s : ファイル送信(要ファイル名)\n" ) ;
- printf( " -r : ファイル受信\n" ) ;
- printf( " -z : サーバーモード\n" ) ;
- printf( " -cリモートコマンド : サーバーにリモートコマンドを送信\n" ) ;
- printf( " -x[path_name] : -sでの格納先パス名\n" ) ;
- printf( " -f : 強制FMR指定\n" ) ;
- printf( " -p : 強制PC98指定\n" ) ;
- printf( " -i : 詳細情報表示\n" ) ;
- }
-
- /*---------------------------------------------------------------------------*/
-
- /* 送信メイン処理 */
- void fp_send()
- {
- int len , loop , i , err ;
- unsigned long f_len ;
- unsigned char *c , *c2 ;
- unsigned char path_name[128] , full_name[128] ;
- FILE *file ;
- int handle ;
- unsigned long speed , f_len_b ;
-
- /* ファイル送信前フラグ送信(^^; */
- buffer[0] = 0x02 ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル送信フラグ送信OK。\n" ) ;
-
- /* ファイル送信フラグ送信(^^; */
- buffer[0] = 0x00 ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル送信フラグ送信OK。\n" ) ;
-
- /* 受信先パス名長送信 */
- len = strlen( path ) ;
- *buffer = (unsigned char)len ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "受信先パス名長送信OK。\n" ) ;
-
- /* 受信先パス名送信 */
- if( len ) {
- if( send_( len , path ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "受信先パス名送信OK。\n" ) ;
- }
-
- /* PATH名取り出し */
- strcpy( path_name , name ) ;
- if( ( c = strrchr( path_name , ':' ) ) == NULL ) {
- c = path_name ;
- }
- if( ( c2 = strrchr( c , '\\' ) ) == NULL ) {
- c2 = c ;
- }
- if( *c2 == ':' || *c2 == '\\' ) *(c2+1) = 0x00 ;
- else strcpy( path_name , "" ) ;
-
- /* ワイルドカード展開 */
- if( ( _dos_findfirst( name , _A_ARCH|_A_RDONLY , &f_name ) ) != 0 ) {
- printf( "送信出来るファイルがありません。\n" ) ;
- buffer[0] = 0x00 ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
- /* 送るデータ有り */
- buffer[0] = 0xff ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
-
- /* 送信処理ループ */
- if( mode != 2 ) printf( " ファイル名 : ファイル長\n" ) ;
- for( ; ; ) {
- ftime( &time_1 ) ;
- err = 0 ;
-
- /* ファイルの長さを調べる _dos_finedではDIETしてあるデータの長さが分からない */
- strcpy( full_name , path_name ) ;
- strcat( full_name , f_name.name ) ;
- if( ( handle = open( full_name , O_RDONLY|O_BINARY ) ) == EOF ) {
- printf( "送信ファイルのオープンに失敗しました(%s)。\n" ,
- full_name ) ;
- buffer[0] = 0x00 ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
- f_len = filelength( handle ) ;
- f_len_b = f_len * 8l ;
- close( handle ) ;
-
- /* ファイルのオープン */
- if( ( file = fopen( full_name , "rb" ) ) == NULL ) {
- printf( "送信ファイルのオープンに失敗しました。\n" ) ;
- buffer[0] = 0x00 ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* 送信データのオープンOK */
- buffer[0] = 0xff ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
-
- /* ファイル名長送信 */
- len = strlen( f_name.name ) ;
- *buffer = (unsigned char)len ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル名長送信OK。\n" ) ;
-
- /* ファイル名送信 */
- strcpy( name , f_name.name ) ;
- if( send_( len , f_name.name ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル名送信OK。\n" ) ;
-
- /* 受信側ファイルチェック */
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- printf( "受信側でファイルのオープンに失敗しました。\n" ) ;
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* ファイル長送信 */
- buffer[0] = f_len / 0x1000000l ;
- buffer[1] = ( f_len & 0x00ff0000l ) / 0x10000l ;
- buffer[2] = ( f_len & 0x0000ff00l ) / 0x100l ;
- buffer[3] = f_len & 0x000000ffl ;
- if( send_( 4 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル長送信OK。\n" ) ;
-
- /* ファイル日付送信 */
- buffer[0] = f_name.wr_date / 0x100 ;
- buffer[1] = f_name.wr_date ;
- if( send_( 2 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル日付送信OK。\n" ) ;
-
- /* ファイル時間送信 */
- buffer[0] = f_name.wr_time / 0x100 ;
- buffer[1] = f_name.wr_time ;
- if( send_( 2 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル時間送信OK。\n" ) ;
-
- /* ファイル属性送信 */
- buffer[0] = f_name.attrib ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "ファイル属性送信OK。\n" ) ;
-
- /* ファイル送信 */
- printf( " %-13.13s : %10ld " , name , f_len ) ;
- loop = ( f_len + BUFFSIZE - 1l ) / BUFFSIZE ;
- for( i = 0 ; i < loop ; i++ ) putch( '.' ) ;
- for( i = 0 ; i < loop ; i++ ) {
- len = fread( buffer , 1 , BUFFSIZE , file ) ;
- if( send_( len , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- /* 受信側ファイル書き込みチェック */
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- printf( "送信失敗!" ) ;
- err = 1 ;
- break ;
- }
- else printf( "\b \b" ) ;
- }
- if( !( err ) ) {
- ftime( &time_2 ) ;
- speed = ( f_len_b / ( ( time_2.time - time_1.time ) * 100l
- + time_2.millitm - time_1.millitm + 1l ) + 5l ) / 10l ;
- printf( "(電送速度:約%ldkbps)" , speed ) ;
- }
-
- /* ファイルのクローズ */
- fclose( file ) ;
-
- /* 受信側ファイルチェック */
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- printf( "×\n" ) ;
- }
- else printf( "○\n" ) ;
-
- /* 次のファイル展開 */
- if( ( _dos_findnext( &f_name ) ) != 0 ) {
- /* おしまい */
- buffer[0] = 0x00 ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- break ;
- }
- /* つづく */
- else {
- buffer[0] = 0xff ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( debug ) printf( "連続送信要求OK。\n" ) ;
- }
- }
-
- }
-
- /* 受信メイン前(^^;処理 */
- void fp_receive0()
- {
- /* ファイル送信前フラグ受信 */
- if( receive_( 1 , buffer ) ) timeout() ;
- if( buffer[0] == 0x02 ) {
- if( debug ) printf( "ファイル送信前フラグ受信OK。\n" ) ;
- }
- else {
- printf( "ファイル送信前フラグが異常です、送信側コマンドを確認してください。\n" ) ;
- rs_init() ;
- exit( -1 ) ;
- }
- }
-
- /* 受信メイン処理 */
- void fp_receive()
- {
- int i , j , len , loop , err ;
- unsigned long f_len ;
- unsigned int f_time , f_date ;
- unsigned char f_attr ;
- unsigned char full_name[128] ;
- FILE *file ;
- int handle ;
- unsigned long speed , f_len_b ;
-
- /* ファイル送信フラグ受信 */
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- if( debug ) printf( "ファイル送信フラグ受信OK。\n" ) ;
- }
- else {
- printf( "ファイル送信フラグが異常です、送信側コマンドを確認してください。\n" ) ;
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* 受信パス名長受信 */
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- len = *buffer ;
- if( debug ) printf( "受信パス名長受信OK。\n" ) ;
- /* 受信パス名受信 */
- if( len ) {
- if( receive_( len , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( ( buffer[len-1] != '\\' ) && ( buffer[len-1] != ':' ) ) {
- buffer[len] = '\\' ;
- buffer[len+1] = 0x00 ;
- }
- else buffer[len] = 0x00 ;
- if( debug ) printf( "受信パス名受信OK。\n" ) ;
- strcpy( path , buffer ) ;
- }
- else strcpy( path , "" ) ;
-
- /* 受信ファイルチェック */
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- printf( "送信側に送るファイルがありません。\n" ) ;
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* 受信処理ループ */
- if( mode != 2 ) printf( " ファイル名 : ファイル長\n" ) ;
- for( ; ; ) {
- ftime( &time_1 ) ;
- err = 0 ;
-
- /* 受信ファイルチェック */
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) {
- printf( "送信側でファイルのオープンに失敗しました。\n" ) ;
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* ファイル名長受信 */
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- len = *buffer ;
- if( debug ) printf( "ファイル名長受信OK。\n" ) ;
-
- /* ファイル名受信 */
- if( receive_( len , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- buffer[len] = 0x00 ;
- if( debug ) printf( "ファイル名受信OK。\n" ) ;
- strcpy( name , buffer ) ;
- strcpy( full_name , path ) ;
- strcat( full_name , name ) ;
-
- /* ファイルのオープン */
- if( ( file = fopen( full_name , "wb" ) ) == NULL ) {
- printf( "受信ファイルのオープンに失敗しました(%s)。\n" , full_name ) ;
- buffer[0] = 0x00 ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( mode == 2 ) return ;
- rs_init() ;
- exit( -1 ) ;
- }
-
- /* オープン OK */
- buffer[0] = 0xff ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
-
- /* ファイル長受信 */
- if( receive_( 4 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- f_len = (unsigned long)buffer[0] * 0x1000000l
- + (unsigned long)buffer[1] * 0x10000l
- + (unsigned long)buffer[2] * 0x100l
- + (unsigned long)buffer[3] ;
- f_len_b = f_len * 8l ;
- if( debug ) printf( "ファイル長受信OK。\n" ) ;
-
- /* ファイル日付受信 */
- if( receive_( 2 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- f_date = (unsigned int)buffer[0] * 0x100
- + (unsigned int)buffer[1] ;
- if( debug ) printf( "ファイル日付受信OK。\n" ) ;
-
- /* ファイル時間受信 */
- if( receive_( 2 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- f_time = (unsigned int)buffer[0] * 0x100
- + (unsigned int)buffer[1] ;
- if( debug ) printf( "ファイル時間受信OK。\n" ) ;
-
- /* ファイル属性受信 */
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- f_attr = buffer[0] ;
- if( debug ) printf( "ファイル属性受信OK。\n" ) ;
-
- /* ファイル受信 */
- printf( " %-13.13s : %10ld " , name , f_len ) ;
- loop = ( f_len + BUFFSIZE - 1l ) / BUFFSIZE ;
- for( i = 0 ; i < loop ; i++ ) putch( '.' ) ;
- for( i = 0 ; i < loop ; i++ ) {
- if( f_len < BUFFSIZE ) j = f_len ;
- else j = BUFFSIZE ;
- if( receive_( j , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( fwrite( buffer , 1 , j , file ) < j ) {
- printf( "書き込み失敗!" ) ;
- err = 1 ;
- buffer[0] = 0x00 ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- break ;
- }
- printf( "\b \b" ) ;
- f_len -= (unsigned long)j ;
- buffer[0] = 0xff ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- }
- if( !( err ) ) {
- ftime( &time_2 ) ;
- speed = ( f_len_b / ( ( time_2.time - time_1.time ) * 100l
- + time_2.millitm - time_1.millitm + 1l ) + 5l ) / 10l ;
- printf( "(電送速度:約%ldkbps)" , speed ) ;
- }
-
- /* ファイルのクローズ */
- fclose( file ) ;
-
- /* ファイルの日時属性設定 */
- if( !( err ) ) {
- if( _dos_open( full_name , O_WRONLY , &handle ) != 0x00 ) {
- printf( "受信ファイルのオープンに失敗しました。" ) ;
- err = 2 ;
- }
- if( _dos_setftime( handle , f_date , f_time ) != 0x00 ) {
- printf( "受信ファイルの日時設定に失敗しました。" ) ;
- err = 3 ;
- }
- if( _dos_setfileattr( full_name , f_attr ) != 0x00 ) {
- printf( "送信ファイルの属性設定に失敗しました。" ) ;
- err = 3 ;
- }
- if( err != 2 ) _dos_close( handle ) ;
- }
-
- /* 受信 NG */
- if( err ) {
- printf( "×\n" ) ;
- unlink( full_name ) ;
- buffer[0] = 0x00 ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- }
- /* 受信 OK */
- else {
- printf( "○\n" ) ;
- buffer[0] = 0xff ;
- if( send_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- }
-
- /* 次のファイルチェック */
- if( receive_( 1 , buffer ) ) {
- if( mode == 2 ) return ;
- timeout() ;
- }
- if( buffer[0] == 0x00 ) break ;
- if( debug ) printf( "連続受信要求OK。\n" ) ;
-
- }
-
- }
-
- /* サーバーメイン処理 */
- void fp_server()
- {
- int len ;
- unsigned long f_len ;
- int handle ;
- FILE *file ;
-
- /* ESCが来るまで無限ループ */
- printf( " ファイル名 : ファイル長\n" ) ;
- for( ; ; ) {
- strcpy( path , "" ) ;
- while( connect_r() ) ;
-
- /* ファイル送信フラグ受信 */
- if( receive_( 1 , buffer ) ) buffer[0] = 0xff ;
- switch( buffer[0] ) {
- case 0x01 : /* サーバーから送信 */
- /* 送信ファイル名長受信 */
- if( receive_( 1 , buffer ) ) break ;
- len = *buffer ;
- if( debug ) printf( "送信ファイル名長受信OK。\n" ) ;
- /* 送信ファイル名受信 */
- if( receive_( len , buffer ) ) break ;
- buffer[len] = 0x00 ;
- if( debug ) printf( "送信ファイル名受信OK。\n" ) ;
- strcpy( name , buffer ) ;
- fp_send() ;
- break ;
- case 0x02 : /* サーバーに受信 */
- fp_receive() ;
- break ;
- case 0x03 : /* リモートコマンド処理 */
- /* リモートコマンド長受信 */
- if( receive_( 1 , buffer ) ) break ;
- len = *buffer ;
- if( debug ) printf( "リモートコマンド長受信OK。\n" ) ;
- /* リモートコマンド受信 */
- if( receive_( len , command ) ) break ;
- command[len] = 0x00 ;
- if( debug ) printf( "リモートコマンド受信OK。\n" ) ;
- /* リモートコマンド実行 */
- strcat( command , ">$$fpli$$.tmp" ) ;
- system( command ) ;
- /* ファイルの長さを調べる _dos_finedではDIETしてあるデータの長さが分からない */
- strcpy( name , "$$fpli$$.tmp" ) ;
- if( ( handle = open( name , O_RDONLY|O_BINARY ) ) == EOF ) {
- f_len = 0l ;
- }
- else {
- f_len = filelength( handle ) ;
- close( handle ) ;
- }
- /* コマンド結果ファイルのオープン */
- file = fopen( name , "rb" ) ;
- /* コマンド結果ファイル長送信 */
- buffer[0] = f_len / 0x1000000l ;
- buffer[1] = ( f_len & 0x00ff0000l ) / 0x10000l ;
- buffer[2] = ( f_len & 0x0000ff00l ) / 0x100l ;
- buffer[3] = f_len & 0x000000ffl ;
- if( send_( 4 , buffer ) ) break ;
- if( debug ) printf( "コマンド結果ファイル長送信OK。\n" ) ;
- /* コマンド結果ファイル送信 */
- for( ; f_len > 0l ; ) {
- len = fread( buffer , 1 , BUFFSIZE , file ) ;
- if( send_( len , buffer ) ) break ;
- f_len -= (unsigned long)len ;
- }
- if( debug ) printf( "コマンド結果ファイル送信OK。\n" ) ;
- fclose( file ) ;
- unlink( name ) ;
- break ;
- default :
- printf( "ファイル送信フラグが異常です、送信側コマンドを確認してください。\n" ) ;
- break ;
- }
- if( debug ) printf( "サーバー処理1シーケンス完了\n" ) ;
- }
-
- }
-
- /* サーバーからの受信処理用(^^;ファイル名送信処理 */
- void fp_file()
- {
- int len ;
-
- /* ファイル名送信フラグ送信(^^; */
- buffer[0] = 0x01 ;
- if( send_( 1 , buffer ) ) timeout() ;
- if( debug ) printf( "ファイル名送信フラグ送信OK。\n" ) ;
-
- /* 受信ファイル名長送信 */
- len = strlen( name ) ;
- *buffer = (unsigned char)len ;
- if( send_( 1 , buffer ) ) timeout() ;
- if( debug ) printf( "受信ファイル名長送信OK。\n" ) ;
-
- /* 受信ファイル名送信 */
- if( send_( len , name ) ) timeout() ;
- if( debug ) printf( "受信ファイル名送信OK。\n" ) ;
-
- }
-
- /* リモートコマンド処理 */
- void fp_command()
- {
- int len , i , j;
- unsigned long f_len ;
- unsigned char *c ;
-
- /* リモートコマンド送信フラグ送信(^^; */
- buffer[0] = 0x03 ;
- if( send_( 1 , buffer ) ) timeout() ;
- if( debug ) printf( "リモートコマンド送信フラグ送信OK。\n" ) ;
-
- /* リモートコマンド長送信 */
- len = strlen( command ) ;
- *buffer = (unsigned char)len ;
- if( send_( 1 , buffer ) ) timeout() ;
- if( debug ) printf( "リモートコマンド長送信OK。\n" ) ;
-
- /* リモートコマンド送信 */
- if( send_( len , command ) ) timeout() ;
- if( debug ) printf( "受信先パス名送信OK(%s)。\n" , command ) ;
-
- /* コマンド結果長受信 */
- while( receive_( 4 , buffer ) ) ;
- f_len = (unsigned long)buffer[0] * 0x1000000l
- + (unsigned long)buffer[1] * 0x10000l
- + (unsigned long)buffer[2] * 0x100l
- + (unsigned long)buffer[3] ;
- if( debug ) printf( "コマンド結果長受信OK。\n" ) ;
-
- /* コマンド結果受信&表示 */
- for( ; f_len > 0l ; ) {
- if( f_len < BUFFSIZE ) i = f_len ;
- else i = BUFFSIZE ;
- if( receive_( i , buffer ) ) timeout() ;
- c = buffer ;
- for( j = 0 ; j < i ; j++ ) {
- putch( *c++ ) ;
- }
- f_len -= (unsigned long)i ;
- }
- if( debug ) printf( "コマンド結果受信OK。\n" ) ;
-
- }
-
- /* タイムアウト停止 */
- void timeout()
- {
- printf( "タイムアウトが発生しました(;_;)。\n" ) ;
- rs_init() ;
- exit( -1 ) ;
-
- }
-
- /* 割り込み処理定義 */
- void sig_out()
- {
-
- printf( "電送処理終了します。\n" ) ;
- rs_init() ;
- exit( -1 ) ;
-
- }
-
- /* タイムアウト値取得処理 */
- void timeset()
- {
- long time_0,time_1,time_2 ;
-
- time_0 = clock() ;
- time_1 = time_0 + 1l ;
- time_2 = time_0 + 2l ;
-
- while( clock() != time_1 ) ;
- for( timeout1 = 0l ; timeout1 < 2000000000l ; timeout1 += 2500l ) {
- if( clock() == time_2 ) break ;
- }
-
- if( debug ) printf( "タイムアウト値は(%ld)です。\n" , timeout1 ) ;
-
- }
-